﻿using System.Windows.Input;
using DependencyAnalysis.DataModel;
using theeg.DependencyAnalysis.CommonAddin.Behaviors;

namespace theeg.DependencyAnalysis.CommonAddin
{
    public partial class AddinWindow
    {
        public static RoutedCommand SortMetricsCommand = new RoutedCommand();
        public static RoutedCommand SelectCommand = new RoutedCommand();

        public AddinWindow()
        {
            InitializeComponent();
        }

        private void SelectExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var descriptor = e.Parameter as IDescriptor;
            if (descriptor != null)
            {
                proximity.ChangeDescriptor(descriptor);
                return;
            }
            dynamic expandoObject = e.Parameter;
            string identifier = expandoObject.Identifier;
            string type = expandoObject.TypeName;
            switch (type)
            {
                case "Module":
                    proximity.ChangeDescriptor(new ModuleDescriptor { Identifier = identifier });
                    break;
                case "Submodule":
                    proximity.ChangeDescriptor(new SubmoduleDescriptor { Identifier = identifier });
                    break;
                case "Type":
                    proximity.ChangeDescriptor(new TypeDescriptor { Identifier = identifier });
                    break;
                case "Member":
                    proximity.ChangeDescriptor(new MemberDescriptor { Identifier = identifier });
                    break;
                default:
                    return;
            }
        }

        private void SortMetricsExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var parameter = (string[])e.Parameter;
            ViewSourceGroup.ToggleSortation(parameter[0], parameter[1]);
        }
    }
}
